import { BasicColumn, FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('system.notice.fields');
const { t: common } = useI18n('common');

export const noticeFields = {
  titile: t('titile'),
  msgCategory: t('msgCategory'),
  sender: t('sender'),
  priority: t('priority'),
  sendStatus: t('sendStatus'),
  sendTime: t('sendTime'),
  cancelTime: t('cancelTime'),
  msgAbstract: t('msgAbstract'),
  endTime: t('endTime'),
  msgType: t('msgType'),
  userIds: t('userIds'),
  msgContent: t('msgContent'),
};
export const columns: BasicColumn[] = [
  {
    title: noticeFields.titile,
    width: 150,
    dataIndex: 'titile',
  },
  {
    title: noticeFields.msgCategory,
    dataIndex: 'msgCategory',
    width: 100,
    customRender: ({ text }) => {
      return render.renderDict(text, 'msg_category');
    },
  },
  {
    title: noticeFields.sender,
    width: 100,
    dataIndex: 'sender',
  },
  {
    title: noticeFields.priority,
    dataIndex: 'priority',
    width: 70,
    customRender: ({ text }) => {
      const color = text == 'L' ? 'blue' : text == 'M' ? 'yellow' : 'red';
      return render.renderTag(render.renderDict(text, 'priority'), color);
    },
  },
  {
    title: noticeFields.msgType,
    dataIndex: 'msgType',
    width: 100,
    customRender: ({ text }) => {
      return render.renderDict(text, 'msg_type');
    },
  },
  {
    title: noticeFields.sendStatus,
    dataIndex: 'sendStatus',
    width: 70,
    customRender: ({ text }) => {
      const color = text == '0' ? 'red' : text == '1' ? 'green' : 'gray';
      return render.renderTag(render.renderDict(text, 'send_status'), color);
    },
  },
  {
    title: noticeFields.sendTime,
    width: 100,
    dataIndex: 'sendTime',
  },
  {
    title: noticeFields.cancelTime,
    width: 100,
    dataIndex: 'cancelTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'titile',
    label: noticeFields.titile,
    component: 'JInput',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'msgCategory',
    label: noticeFields.msgCategory,
    required: true,
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      type: 'radio',
      dictCode: 'msg_category',
    },
  },
  {
    field: 'titile',
    label: noticeFields.titile,
    component: 'Input',
    required: true,
  },
  {
    field: 'msgAbstract',
    label: noticeFields.msgAbstract,
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'endTime',
    label: noticeFields.endTime,
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: common('chooseText') + noticeFields.endTime,
    },
    dynamicRules: ({ model }) => rules.endTime(model.startTime, true),
  },
  {
    field: 'msgType',
    label: noticeFields.msgType,
    defaultValue: 'ALL',
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      type: 'radio',
      dictCode: 'msg_type',
      placeholder: common('chooseText') + noticeFields.msgType,
    },
  },
  {
    field: 'userIds',
    label: '指定用户',
    component: 'JSelectUser',
    required: true,
    componentProps: {
      rowKey: 'id',
      labelKey: 'username',
    },
    ifShow: ({ values }) => values.msgType == 'USER',
  },
  {
    field: 'priority',
    label: noticeFields.priority,
    defaultValue: 'H',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'priority',
      type: 'radio',
      placeholder: common('chooseText') + noticeFields.priority,
    },
  },
  {
    field: 'msgContent',
    label: noticeFields.msgContent,
    component: 'Input',
    render: render.renderTinymce,
  },
];
